package top.yxf.spring.support;

import top.yxf.spring.BeanFactory;
import top.yxf.spring.BeansException;
import top.yxf.spring.config.BeanDefinition;

/**
 * @author xs.wu
 */
public abstract class AbstractBeanFactory  extends DefaultSingletonBeanRegistry implements BeanFactory {

    @Override
    public Object getBean(String name) throws BeansException {
        Object singleton = getSingleton(name);
        if (singleton != null) {
            return singleton;
        }
        BeanDefinition beanDefinition = getBeanDefinition(name);
        return createBean(name, beanDefinition);
    }


    protected abstract BeanDefinition getBeanDefinition(String name) throws BeansException;

    protected  abstract Object createBean(String beanName, BeanDefinition beanDefinition) throws BeansException;
}
